#include <iostream>
using namespace std;
const int N = 100005;
int n, ans;
int arr[N];
int main(){
	cin >> n;
	for (int i = 0; i < n; i++) cin >> arr[i];
	int flag = 1;
	while(flag){
		int flag1 = 0;
		for (int i = 0; i <= n; i++){
			if (arr[i] != 0){
				arr[i]--;
				flag1 = 1;
			}
			else if (flag1){
				ans++;
				flag1 = 0;
			}
		}
		flag = 0;
		for (int i = 0; i < n; i++){
			if (arr[i] != 0){
				flag = 1;
			}
		}	
	}
	cout << ans << endl;
	return 0;
}
